<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">   
    <link href="css/bootstrap.css" rel="stylesheet">
    <link href="css/list.css" rel="stylesheet">
    <link href="css/public.css" rel="stylesheet">
    <title>列表页</title>
</head>
<body>


<div class="nav top">
    <ul class="nav navbar-nav navbar-right top-list">
        <li><a href="#">关于我们</a></li>
        <li><a href="regist.jsp">注册</a></li>
        <li><a href="login.jsp">登录</a></li>
    </ul>
</div>

<div class="container main-container">
    <div class="nav-img">
        <img src="img/index-nav.png">
    </div>
    <div class="search">
         <form action="<c:url value='/SeedServlet'/>" method="post">
         <input type="hidden" name="method" value="query"/>
            <div class="form-group">
                <input type="search"  name="sname" class="form-control">
                <button class="btn-default search-btn"></button>
            </div>
        </form>
    </div>

    <nav class="nav nav-main">

        <ul class="nav navbar-nav nav-list">
           <li><a href="index">首页</a></li>
             <li><a href="<c:url value='/AdminSeedServlet?method=addPre1'/>">上传产品</a></li>
           <li><a href="<c:url value='/SeedServlet?method=findAll'/>">产品列页</a></li>
            <li><a href="<c:url value='/CategoryServlet?method=findAll'/>">所有分类</a></li>
            <li><a href="<c:url value='/SeedServlet?method=messageGet'/>">留言板</a></li>
        </ul>
    </nav>

    <!--以上在后台设计的时候放到一个页面中，让别的页面去引用它-->

 
    <div class="row">
        <div class="col-md-9">
            <div class="panel panel-green">
                <div class="panel-heading">
                    <div class="panel-title">
                        <span class="glyphicon glyphicon-align-right">&nbsp;</span>产品列表
                    </div>
                </div>
         <c:forEach items="${pb.beanList }" var="seed" >
                <div class="panel panel-body">
                    <div class="list-product">
                        <div class="list-left col-md-6">
                            <a href="<c:url value='/SeedServlet?method=load&sid=${seed.sid }'/>"><img src="upfile/${seed.image }"/></a>
                            <ul>
                               <li>${seed.sname }</li>
		    			       <li>零售价格：${seed.price }元</li>
		    			      <li>品种编号：${seed.sid }</li>
		    			       <li>包装规格：${seed.large }g/袋</li>
                            </ul>
                            <a id="${seed.sid}" class="compare btn btn-primary">对比</a>
                            <a href="<c:url value='SeedServlet?method=commentAdd&sid=${seed.sid }'/>" class="btn btn-primary">评论</a>
                        </div>
                        <div class="list-right col-md-6">
                            <h3>特征特性：</h3>
                            <p>${seed.xiangxi }</p>
                            <a href="<c:url value='/SeedServlet?method=load&sid=${seed.sid }'/>">[详细介绍]</a>
                        </div>
                    </div> 
                </div>
                
                </c:forEach>
            </div>
         
            <nav class="col-md-offset-2">
                <ul class="pagination">
                          
                     <c:if test="${pb.pc>1 }">
                    <li><a href="<c:url value='/SeedServlet?method=findAll&pc=${pb.pc+1 }'/>">&laquo;</a></li>
                       </c:if>       
                    <li><a  href="<c:url value='/SeedServlet?method=findAll&pc=1'/>">首页</a></li>
                    <c:if test="${pb.pc>1 }">
                    <li><a href="<c:url value='/SeedServlet?method=findAll&pc=${pb.pc-1 }'/>">上一页</a></li>
                    
                    </c:if>
                    <%-- 计算begin、end --%>
<c:choose>
	<%-- 如果总页数不足10页，那么把所有的页数都显示出来！ --%>
	<c:when test="${pb.tp <= 10 }">
		<c:set var="begin" value="1" />
		<c:set var="end" value="${pb.tp }" />
	</c:when>
	<c:otherwise>
		<%-- 当总页数>10时，通过公式计算出begin和end --%>
		<c:set var="begin" value="${pb.pc-5 }" />
		<c:set var="end" value="${pb.pc+4 }" />	
		<%-- 头溢出 --%>
		<c:if test="${begin < 1 }">
			<c:set var="begin" value="1" />
			<c:set var="end" value="10" />
		</c:if>	
		<%-- 尾溢出 --%>
		<c:if test="${end > pb.tp }">
			<c:set var="begin" value="${pb.tp - 9 }" />
			<c:set var="end" value="${pb.tp }" />
		</c:if>	
	</c:otherwise>
</c:choose>
<%-- 循环遍历页码列表 --%>
<c:forEach var="i" begin="${begin }" end="${end }">
	
	<c:choose>
	<c:when test="${i eq pb.pc }">
	<li class="active"><a href="<c:url value='/SeedServlet?method=findAll&pc=${i }'/>">${i }</a></li>
	</c:when>
	<c:otherwise>
	<li><a href="<c:url value='/SeedServlet?method=findAll&pc=${i }'/>">${i }</a></li>
	</c:otherwise>
	</c:choose>
</c:forEach>
                    <c:if test="${pb.pc<pb.tp }">
                    <li><a href="<c:url value='/SeedServlet?method=findAll&pc=${pb.pc+1 }'/>">下一页</a></li>
                     </c:if>
                    <li><a href="<c:url value='/SeedServlet?method=findAll&pc=${pb.tp}'/>">尾页</a></li>
                     <c:if test="${pb.pc<pb.tp }">
                    <li><a href="<c:url value='/SeedServlet?method=findAll&pc=${pb.pc+1 }'/>">&raquo;</a></li>
                    </c:if>
                </ul>
            </nav>
           
        </div>
         
        <!--下列是一个右侧栏，设计的时候也要单独放一个文件中-->
        <div class="col-md-3">
            <div class="panel panel-green">
                <div class="panel-heading">
                    <div class="panel-title">
                        <span class="glyphicon glyphicon-tag">&nbsp;</span>种子分类
                    </div>
                </div>
                <div class="panel panel-body recommend">
                    <ul>
                         <li><a href="<c:url value='CategoryServlet?method=findAll&cid=1'/>">蔬菜种子（品种：7个）</a></li>
                          <li><a href="<c:url value='CategoryServlet?method=findAll&cid=2'/>">玉米种子（品种：7个）</a></li>
                         <li><a href="<c:url value='CategoryServlet?method=findAll&cid=3'/>">花卉种子（品种：7个）</a></li>
                          <li><a href="<c:url value='CategoryServlet?method=findAll&cid=4'/>">小麦种子（品种：7个）</a></li>
                          
                    </ul>
                </div>
            </div>


            <div class="panel panel-green">
                <div class="panel-heading">
                    <div class="panel-title">
                        <span class="glyphicon glyphicon-tag">&nbsp;</span>种子分类
                    </div>
                </div>
                <div class="panel panel-body recommend">
                    <ul>
                           <li><a href="<c:url value='CategoryServlet?method=findAll&cid=1'/>">蔬菜种子（品种：7个）</a></li>
                           <li><a href="<c:url value='CategoryServlet?method=findAll&cid=2'/>">玉米种子（品种：7个）</a></li>
                         <li><a href="<c:url value='CategoryServlet?method=findAll&cid=3'/>">花卉种子（品种：7个）</a></li>
                          <li><a href="<c:url value='CategoryServlet?method=findAll&cid=4'/>">小麦种子（品种：7个）</a></li>
                          
                    </ul>
                </div>
            </div>

            <div class="panel panel-green">
                <div class="panel-heading">
                    <div class="panel-title">
                        <span class="glyphicon glyphicon-tag">&nbsp;</span>种子分类
                    </div>
                </div>
                <div class="panel panel-body recommend">
                    <ul>
                           <li><a href="<c:url value='CategoryServlet?method=findAll&cid=1'/>">蔬菜种子（品种：7个）</a></li>
                           <li><a href="<c:url value='CategoryServlet?method=findAll&cid=2'/>">玉米种子（品种：7个）</a></li>
                         <li><a href="<c:url value='CategoryServlet?method=findAll&cid=3'/>">花卉种子（品种：7个）</a></li>
                          <li><a href="<c:url value='CategoryServlet?method=findAll&cid=4'/>">小麦种子（品种：7个）</a></li>
                         
                           
                    </ul>
                </div>
            </div>
        </div>
    </div>

</div>






    <!--以下单独放单独引用-->
    <div class="row">
        <div class="col-md-12">
            <div class="public-bottom">
                <div>
                    <p>郑州轻工业学院科学大道166号 计算机与通信工程学院 电子信息工程学院 大学生科技创业中心 </p>
                    <p style="text-align: center">联系电话：18790802327 &nbsp;&nbsp;&nbsp;版权所有：大学生科技创业中心</p>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="tip">
	
</div>
</body>
<script src="js/jquery.min.js"></script>
<script>
$('.compare').click(function(){
	$.ajax({
		url:"SeedServlet?method=compare",
		data:{"sid":this.id},
		success:function(data){
			$('.tip').html(data);
			$('.tip').css('display','block');
			setTimeout("$('.tip').css('display','none')",3000);
		}
	})
})
</script>
</html>